//
//  BRHud.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/9/1.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRHud.h"
#import "BRHudLoadingView.h"

@implementation BRHud

+ (QMUITips *)showInView:(UIView *)parentView {
    QMUITips *hud = [QMUITips showLoadingInView:parentView];
    
//    [hud showLoading];
    
    return hud;
}

+ (QMUITips *)showHud {
    return [[self class] showInView:DefaultTipsParentView];
}

+ (QMUITips *)showTips:(NSString *)text {
    return [[self class] show:text inView:DefaultTipsParentView];
}

+ (QMUITips *)show:(NSString *)text inView:(UIView *)parentView {
    QMUITips *hud = nil;
    if (text.length > 0) {
        hud = [QMUITips showWithText:text inView:parentView];
    }else {
        hud = [QMUITips showLoadingInView:parentView];
    }
    
//    [hud showLoading];
    
    return hud;
}

+ (void)showAuto:(NSString *)text {
    [[self class] showAuto:text inView:DefaultTipsParentView];
}

+ (void)showAuto:(NSString *)text inView:(UIView *)parentView {
    
    [[self class] showAuto:text inView:parentView hideAfterDelay:[QMUITips smartDelaySecondsForTipsText:text]];
}

+ (void)showAutoSuccInView:(UIView *)parentView {
    NSString *text = Localized(@"public_success");
    [[self class] showAuto:text inView:parentView hideAfterDelay:[QMUITips smartDelaySecondsForTipsText:text]];
}

+ (void)showAuto:(NSString *)text inView:(UIView *)parentView hideAfterDelay:(NSTimeInterval)time {
    
    if (text.length > 0) {
        [QMUITips showWithText:text inView:parentView hideAfterDelay:time];
    }else {
        [QMUITips showLoadingInView:parentView hideAfterDelay:time];
    }
}

+ (void)showAuto:(NSString *)imgName title:(NSString *)title subTitle:(NSString *)subTitle  inView:(UIView *)parentView {
    
    QMUITips *tips = [QMUITips createTipsToView:parentView];
    tips.toastPosition = QMUIToastViewPositionBottom;
    QMUIToastAnimator *customAnimator = [[QMUIToastAnimator alloc] initWithToastView:tips];
    tips.toastAnimator = customAnimator;
    QMUIToastContentView *customContentView = [[QMUIToastContentView alloc] init];
//    if (imgName.length > 0) {
//        customContentView.
//    }
//    self.imageView.image = image;
    customContentView.textLabel.text = title;
    customContentView.detailTextLabel.text = subTitle;
//    [customContentView.imageView sizeToFit];
//    [customContentView.textLabel sizeToFit];
//    [customContentView.detailTextLabel sizeToFit];
//    [customContentView setNeedsLayout];
//    [customContentView layoutIfNeeded];
//    customContentView ren
//    [customContentView renderWithImage:[UIImage imageNamed:@""] text:title detailText:subTitle];
    tips.contentView = customContentView;
    [tips showAnimated:YES];
    [tips hideAnimated:YES afterDelay:4];
}

+ (void)hidden {
    [QMUITips hideAllTips];
}

+ (void)hiddenInView:(UIView *)parentView {
    [QMUITips hideAllTipsInView:parentView];
}

+ (QMUITips *)showLoad:(NSString *)title inView:(UIView *)parentView {
    return [BRHud showLoad:title hideAfterDelay:0 inView:parentView];
}

+ (QMUITips *)showLoad:(NSString *)title hideAfterDelay:(NSInteger)time inView:(UIView *)parentView {
    QMUITips *tips = [QMUITips createTipsToView:parentView];
    tips.toastPosition = QMUIToastViewPositionCenter;
    BRHudLoadingView *loadview = [[BRHudLoadingView alloc] init];
    loadview.title = title;
    [loadview layoutIfNeeded];
    [loadview start];
    tips.contentView = loadview;
    [tips showAnimated:YES];
    if (time != 0) [tips hideAnimated:YES afterDelay:time];
    return tips;
}

+ (QMUITips *)showLoadOver:(NSString *)title img:(NSString *)imgStr hideAfterDelay:(NSInteger)time inView:(UIView *)parentView {
    QMUITips *tips = [QMUITips createTipsToView:parentView];
    tips.toastPosition = QMUIToastViewPositionCenter;
    
    tips.maskView.backgroundColor = UIColor.clearColor;
    BRHudLoadingView *loadview = [[BRHudLoadingView alloc] init];
    [loadview br_setTitle:title img:imgStr];
    [loadview layoutIfNeeded];
    tips.contentView = loadview;
//    tips.contentView.backgroundColorz = kColorShadow(0.4);
    [tips showAnimated:YES];
    if (time != 0) [tips hideAnimated:YES afterDelay:time];
    return tips;
}

+ (QMUITips *)showLoadOverSucc:(NSString *)title inView:(UIView *)parentView {
    
    return [BRHud showLoadOver:title img:@"hud_succ" hideAfterDelay:2 inView:parentView];
}

@end
